package com.session3;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.HeadlessException;

import javax.swing.JColorChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.border.Border;
import javax.swing.colorchooser.ColorSelectionModel;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

public class JColorDemo extends JFrame implements ChangeListener {
	private JColorChooser colorChosse;
	private JLabel lbltext;
	private ColorSelectionModel cmodel;
	
	public JColorDemo() {
	}
	public void createForm(){
		this.lbltext = new JLabel("Pham Van Viet");
		this.colorChosse = new JColorChooser();
		this.getContentPane().add(this.lbltext, BorderLayout.NORTH);
		this.getContentPane().add(this.colorChosse, BorderLayout.CENTER);
		this.cmodel = this.colorChosse.getSelectionModel();
		
		this.cmodel.addChangeListener(this);
	}
	public void showForm(){
		this.setTitle("Demo");
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.setSize(400,300);
		this.setVisible(true);
	}
	@Override
	public void stateChanged(ChangeEvent e) {
		if(e.getSource() == this.cmodel){
			this.lbltext.setForeground(this.colorChosse.getColor());
		}
	}
	public static void main(String[] args) {
		JColorDemo c = new JColorDemo();
		c.createForm();
		c.showForm();
	}

}
